#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

int N;
const int maxn = 1e5 + 10;
int feel[maxn];
int sum[maxn];
int st[maxn][int(log2(maxn)) + 1];
int ans = 0;

int query(int l,int r){
    int k = log2(r-l+1);
    return min(st[l][k],st[r-(1<<k)+1][k]);
}

int main()
{
    cin >> N;
    //st = new int*[N+1];
    for (int i = 1; i <= N; i++)
    {
        //st[i] = new int[int(log2(N))+1];
        cin >> feel[i];
        st[i][0] = feel[i];
        sum[i] = sum[i - 1] + feel[i];
        
    }
    for(int j=1;j<=log2(N);j++){
        for(int i=1;i+(1<<j)-1<=N;i++){
            st[i][j] = min(st[i][j-1],st[i+(1<<(j-1))][j-1]);
        }
    }
    for(int i=1;i<=N;i++){
        for(int j=i;j<=N;j++){
            int tmp = query(i,j);
            ans  = max(ans,(sum[j]-sum[i-1])*tmp);
        }
    }
    // for(int i=1;i<=N;i++){
    //     delete[] st[i];
    // }
    // delete st;
    cout << ans << endl;
    system("pause");
    return 0;
}
